import useUserStore from "@store/modules/user"
export default {
  mounted(el:any, binding:any) {
    const permission = binding.value
    const userStore = useUserStore();
    const hasPermission = checkPermission(userStore.userInfo.permissions,permission)
    if (!hasPermission) {
      //el.parentNode?.removeChild(el) // 如果没有权限，移除元素

      el.disabled = true // 如果没有权限，设置为不可用
      el.classList.add('is-disabled')
    }
  },
}

// 权限检查函数
function checkPermission(permissionList: string[], permission: string) {
  if(permission){
      return permissionList.includes(permission) || permissionList.includes("*:*:*")
  }
  console.log("指令v-has-permission不能为空")
  return false;
}
